package analyzer

import (
    "github.com/astaxie/beego"
    "cloud_worm/util/umodels/mysqldb"
    "cloud_worm/util/uhttp"
)

// @Description: 执行分析控制器
type DoAnalyzerController struct {
    beego.Controller
}

/**
 @Description：先拉取所有的list
 @Param:
 @Return：
 */
func (d *DoAnalyzerController) DoAnalyzer() {
    ip := d.GetString("ip", mysqldb.SelectStrAll)
    wolId := d.GetString("wolid", mysqldb.SelectStrAll)
    wpId, err := d.GetInt64("weaponid")
    taskId := d.GetString("taskid", mysqldb.SelectStrAll)
    name := d.GetString("name", mysqldb.SelectStrAll)
    if ip == mysqldb.SelectStrAll || wolId == mysqldb.SelectStrAll ||
        taskId == mysqldb.SelectStrAll || name == mysqldb.SelectStrAll || err != nil {
        d.Data["json"] = uhttp.CreateErrResponse(uhttp.RespCodeParamErr, "input params error.", nil)
        d.ServeJSON()
        return
    }

    ci := &ComputeItem{
        Name: name,
        WormId: wolId,
        Ip: ip,
        WeaponId: wpId,
        TaskId: taskId,
    }
    ComputeQueueInstance().MsgQ.Push(ci)

    d.Data["json"] = uhttp.CreateOkResponse(nil)
    d.ServeJSON()
    return
}

// @Description: 执行分析控制器
type DoTaskAlertDeal struct {
    beego.Controller
}

func (d *DoTaskAlertDeal) DoTaskAlert() {
    taskId := d.GetString("task_id", mysqldb.SelectStrAll)
    if taskId == mysqldb.SelectStrAll {
        d.Data["json"] = uhttp.CreateErrResponse(uhttp.RespCodeParamErr, "input params error.", nil)
        d.ServeJSON()
        return
    }

    c := &ComputeTaskAlerts{
        TaskId: taskId,
    }
    ComputeQueueInstance().MsgQ.Push(c)
    d.Data["json"] = uhttp.CreateOkResponse(nil)
    d.ServeJSON()
    return
}